package com.boil.qz.safekavass.pojo;

import com.boil.util.Constants;
import com.boil.util.Utils;

import java.util.ArrayList;
import java.util.LinkedHashSet;
import java.util.List;
import java.util.Set;

/**
 * Created by ChenYong on 2017-08-09.
 * <br>
 * 用户角色关联映射实体类。
 */
public class UserRoleVo extends BaseVo {
    /**
     * 登录 ID
     */
    private String loginid;
    /**
     * 姓名
     */
    private String loginName;
    /**
     * 用户拥有的角色
     */
    private String roleNames;
    /**
     * 用户拥有的角色代码
     */
    private String roleCodes;
    /**
     * 用户拥有的资源
     */
    private String resourceNames;
    /**
     * 用户拥有的权限
     */
    private String permissionCodes;
    /**
     * 权限分配状态：0-未分配；1-已分配
     */
    private Integer permissionStatus;

    /**
     * 默认构造器。
     */
    public UserRoleVo() {
        super();
    }

    public String getLoginid() {
        return loginid;
    }

    public void setLoginid(String loginid) {
        this.loginid = loginid;
    }

    public String getLoginName() {
        return loginName;
    }

    public void setLoginName(String loginName) {
        this.loginName = loginName;
    }

    public String getRoleNames() {
        return roleNames;
    }

    public void setRoleNames(String roleNames) {
        // 剔除重复的角色名称
        List<String> list = Utils.parseStr2List(roleNames, Constants.SPLIT_1_RE, String.class);
        Set<String> set = new LinkedHashSet<String>(list);

        list = new ArrayList<String>(set);

        this.roleNames = Utils.parseList2Str(list, Constants.SPLIT_1);
    }

    public String getRoleCodes() {
        return roleCodes;
    }

    public void setRoleCodes(String roleCodes) {
        // 剔除重复的角色代码
        List<String> list = Utils.parseStr2List(roleCodes, Constants.SPLIT_1_RE, String.class);
        Set<String> set = new LinkedHashSet<String>(list);

        list = new ArrayList<String>(set);

        this.roleCodes = Utils.parseList2Str(list, Constants.SPLIT_1);
    }

    public String getResourceNames() {
        return resourceNames;
    }

    public void setResourceNames(String resourceNames) {
        // 剔除重复的资源名称
        List<String> list = Utils.parseStr2List(resourceNames, Constants.SPLIT_1_RE, String.class);
        Set<String> set = new LinkedHashSet<String>(list);

        list = new ArrayList<String>(set);

        this.resourceNames = Utils.parseList2Str(list, Constants.SPLIT_1);
    }

    public String getPermissionCodes() {
        return permissionCodes;
    }

    public void setPermissionCodes(String permissionCodes) {
        // 剔除重复的权限代码
        List<String> list = Utils.parseStr2List(permissionCodes, Constants.SPLIT_1_RE, String.class);
        Set<String> set = new LinkedHashSet<String>(list);

        list = new ArrayList<String>(set);

        this.permissionCodes = Utils.parseList2Str(list, Constants.SPLIT_1);
    }

    public Integer getPermissionStatus() {
        return permissionStatus;
    }

    public void setPermissionStatus(Integer permissionStatus) {
        this.permissionStatus = permissionStatus;
    }

    @Override
    public String toString() {
        final StringBuffer sb = new StringBuffer("UserRoleVo{");
        sb.append("loginid='").append(loginid).append('\'');
        sb.append(", loginName='").append(loginName).append('\'');
        sb.append(", roleNames='").append(roleNames).append('\'');
        sb.append(", roleCodes='").append(roleCodes).append('\'');
        sb.append(", resourceNames='").append(resourceNames).append('\'');
        sb.append(", permissionCodes='").append(permissionCodes).append('\'');
        sb.append(", permissionStatus=").append(permissionStatus);
        sb.append(", id=").append(id);
        sb.append('}');
        return sb.toString();
    }
}